package simtester.server

import java.util.Date

class TestCase {
    static belongsTo = [owner: User, team: Team]

    String name
    String script
    Date dateCreated
    Date lastUpdated
	List<Category> categories = []
	String type
    
    static constraints = {
        name size: 3..25, blank: false//, unique: true
    }
    
    static mapping = {
        name index: true//, indexAttributes: [unique: true, dropDups: true]
    }
	
	static embedded = ['categories']
	
	def findCatValue(category) {
		def cat = categories.find { it.name == category }
		
		if (cat) {
			cat.value
		} else {
			null
		}
	}
	
	def findCatNames() {
		categories.collect { it.name }
	}
	
	def setCategory(key, value) {
		def cat = categories.find { it.name == key }
		if (cat) {
			cat.value = value
		} else {
			categories << new Category(name: key, value: value)
		}
	}
}
